//
//  MessageAction.m
//  XPComDemo
//
//  Created by Junjie Gong on 12-5-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#include "MessageAction.h"
#import <Foundation/Foundation.h>
#import "JpToolbar.h"

MessageAction::MessageAction()
{
    
}

void MessageAction::setToolbar(void* bar){
    toolbar = bar;
}

void MessageAction::OnAction(const char *actionName, const char *param)
{
#define nameFlag    @"action-name"
#define paramFlag   @"param-name"
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
    NSString *n = [NSString stringWithUTF8String:actionName];
    [dict setObject:n forKey:nameFlag];
    if (param) {
        NSString *p = [NSString stringWithUTF8String:param];
        [dict setObject:p forKey:paramFlag];
    }

    
    JpToolbar* t = (JpToolbar *)toolbar;
    NSLog(@"start send message");
    //[t sendMessageWithObject:dict];
    [t postMessageWithObject:dict];
    
    NSLog(@"end send message");
    
//    NSString *n = [NSString stringWithUTF8String:actionName];
//    NSMutableDictionary *dict = nil;
//    if (param) {
//        NSString *p = [NSString stringWithUTF8String:param];
//        [dict setObject:p forKey:@"message-parameter"];
//    }
//    
//    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
//    [nc postNotificationName:@"toolbar_message_handler" object:n userInfo:dict];
}